const app = getApp()
Component({
  options: {
    addGlobalClass: true,
  },
  data: {
    totalCount: 0,
    buyCount: 0,
    saleCount: 0,
    userInfo:app.globalData.userInfo
  },
  attached() {
    wx.cloud.database().collection('yw_commodity').where({
      userId:app.globalData.userInfo._openid,
      status_l:"已完成"
    }).get().then(res=>{
        this.setData({
          saleCount:res.data.length
        })
        wx.cloud.database().collection('yw_commodity').where({
          userId2:app.globalData.userInfo._id,
          status_l:"已完成"
        }).get().then(res=>{
          this.setData({
            buyCount:res.data.length
          })
          this.setData({
            totalCount:this.data.saleCount+this.data.buyCount
          })
        })
    })
    this.setData({
      userInfo:app.globalData.userInfo
    })
  },
  methods: {
    // 复制
    CopyLink(e) {
      wx.setClipboardData({
        data: e.currentTarget.dataset.link,
        success: res => {
          wx.showToast({
            title: '已复制',
            duration: 1000,
          })
        }
      })
    },
    ls2(){
      wx.navigateTo({
        url: '/pages/history/history',
      })
    },
    ls3(){

    },
    coutNum(e) {
      if (e > 1000 && e < 10000) {
        e = (e / 1000).toFixed(1) + 'k'
      }
      if (e > 10000) {
        e = (e / 10000).toFixed(1) + 'W'
      }
      return e
    },
    deleteUser(e) {
      wx.showModal({
        title:"注销用户",
        content:'注销账户后该账户所有信息将会被清除！',
        complete:res=>{
          if(res.confirm){
            wx.clearStorage({
              success: (res) => {
                app.globalData.auth=false
                  wx.redirectTo({
                    url: '/pages/index/index',
                  })
              },
            })
          }
        }
      })
    },
    showModal(e) {
      this.setData({
        modalName: e.currentTarget.dataset.target
      })
    },
    hideModal(e) {
      this.setData({
        modalName: null
      })
    },
    showQrcode() {
      wx.previewImage({
        urls: ['https://image.weilanwl.com/color2.0/zanCode.jpg'],
        current: 'https://image.weilanwl.com/color2.0/zanCode.jpg' // 当前显示图片的http链接      
      })
    },
    jump_to(e){
        wx.navigateTo({
          url: '../my/'+e.target.dataset.y+'/'+e.target.dataset.y
        })
    }
  }
})